package brinaryTree;

import java.util.LinkedList;
import java.util.Queue;

public class N559_MaxDepthOfNArrayTree {
    public int maxDepth(Node root) {
        if (root == null) return 0;
        int depth = 0;
        Queue<Node> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                Node node = queue.poll();
                for (int j = 0; j < node.children.size(); j++) {
                    if (node.children.get(i) != null) {
                        queue.offer(node.children.get(i));
                    }
                }
            }
        }
        return depth;
    }
}
